package com.zhang.paymentdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhang.paymentdemo.entity.OrderInfo;
import com.zhang.paymentdemo.mapper.OrderInfoMapper;
import com.zhang.paymentdemo.service.OrderInfoService;
import com.zhang.paymentdemo.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName OrderController
 * @Description 订单
 * @Author zhanghongguo
 * @Date 2022/1/8 17:21
 * @Version 1.0
 */
@Api(tags = "订单信息")
@CrossOrigin
@RestController
@RequestMapping(value = "api/order-info")
public class OrderController {
    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @ApiOperation("创建订单")
    @RequestMapping(value = "createOrder",method = RequestMethod.POST)
    private R createOrder(){
        int order = orderInfoService.createOrder();
        return order>0?R.ok():R.error();
    }
    @ApiOperation("订单列表")
    @RequestMapping(value = "list",method = RequestMethod.GET)
    private R getOrderList(){
        QueryWrapper<OrderInfo> queryWrapper = new QueryWrapper<OrderInfo>().orderByDesc("create_time");
        List<OrderInfo> list = orderInfoMapper.selectList(queryWrapper);
        return R.ok().data("list",list);
    }
}
